#import "PreviewView.h"

@implementation PreviewView

- (id)initWithFrame:(NSRect)frameRect
{
	if ((self = [super initWithFrame:frameRect]) != nil) {
		// Add initialization code here
	}
	return self;
}

- (IBAction)changeSize:(id)sender
{
	[self setNeedsDisplay:YES];
}

- (void)drawRect:(NSRect)rect
{
	if (!imageToDraw) {
		return;
	}
	
	NSRect drawingRect;
	NSRect imageRect;
	imageRect.origin = NSZeroPoint;
	imageRect.size = [imageToDraw size];
	
	imageRect.size.width;
	imageRect.size.height;
	
	float ratio = [sizeSlider floatValue] / imageRect.size.width;
	drawingRect = imageRect;
	drawingRect.size.width *= ratio;
	drawingRect.size.height *= ratio;
	
	[imageToDraw drawInRect:drawingRect
				   fromRect:imageRect
				  operation:NSCompositeSourceOver
				   fraction:1.0];
}

- (void)setImageToDraw:(NSImage*)aImage
{
	[imageToDraw autorelease];
	imageToDraw = [aImage retain];
}

- (void) dealloc {
	[imageToDraw release];
	[super dealloc];
}

@end
